- /* slflsqrt.cpp by K.Tsuru */
- // function ID = 2004 DRADIX
- /*******************************************
- SLong class
- Get a square root of SLong N.
- *sgn = sign of (N - q*q). sgn >= 0
- If N is a complete square number, sgn = 0.
- *******************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- SLong LSqrt(const SLong& N, int* sgn){
- RealSize C;
- // change the effective figures for a time.
- uint ef = N.Head() + 1u;
- C.SetEffFig(ef, C.TEMP_EXTEND);
- SDouble sq(N);
- sq = DDAdd(Sqrt(sq), ROUND_DBL_INT); // use Newton method.
-
- SLong q, r;
- q = sq; // need the information of effective figures.
- C.SetEffFig(0); // restore the effective figures.
- r = N - q*q;
-
- if(r.Sign(2004) < 0){
- q -= 1.0; r = N - q*q;
- if( r.Sign() < 0 ) r.SetError(r.VERIFY, "LSqrt", 2004);
- }
- if(sgn != NULL) *sgn = r.Sign(); // = 1 or 0
- return q;
- }
slflsqrt.cpp : last modifiled at 2015/11/27 14:04:29(881 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).